package servlets;

import java.io.IOException;
import javax.inject.Inject;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import sessions.IUserAccountSession;

/**
 * Trabalho PD - 2014/2015
 * @author a21210380 a21210392
 */
@WebServlet("/login.html")
public class LoginPageServlet extends ServletBase {
    
    @Inject private IUserAccountSession userAccountSession;
    
    public LoginPageServlet() {
        super("Login", null, null, null);
    }

    @Override
    protected void onGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        if(userAccountSession.isVisitor()) {
            callJsp(JSP_LOGIN, req, resp);
        } else {
            redirect("/Trabalho_PD/homepage.html", resp);
        }
    }

    @Override
    protected void onPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        callJsp(JSP_LOGIN, req, resp);
    }
}
